package com.wisdom;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.LocalActivityManager;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.ToggleButton;

import android.view.GestureDetector.OnGestureListener;
//import com.example.slidingmenu.R;
//import com.example.slidingmenu.RightFragment;
//import com.example.slidingmenu.BaseActivity;




import com.wisdom.http.HttpRequestUrl;
import com.wisdom.utils.ExitUtils;
import com.wisdom.utils.MoveBg;
import com.wisdom.vo.Users;

public class MainActivity extends BaseActivity implements OnGestureListener {
	TabHost tabHost;
	TabHost.TabSpec tabSpec;
	RadioGroup radioGroup;
	RelativeLayout bottom_layout;
	ImageView img;
	int startLeft;
	
	
	
    ViewPager viewPager;
	ArrayList<View> list;
	ViewGroup main, group;
	ImageView imageView;
	ImageView[] imageViews;
	private static int c_id = 0;
	
	
	
	RelativeLayout layout;
	RelativeLayout layout_news_main;
	LayoutInflater inflater;
	Intent intent;
	View page;//用来存放顶部具体分类的view
	
	TextView tv_front;//需要移动的View

	ToggleButton menuBtn,settingBtn;
	
	TextView tv_bar_news;
	TextView tv_bar_sport;
	TextView tv_bar_play;
	TextView tv_bar_finance;
	TextView tv_bar_science;
	TextView tv_bar_more;
	
	public static final int LOGIN_RESULT = 3;
	
	
	//RelativeLayout followMenuLayout;	


	int avg_width = 0;// 用于记录平均每个标签的宽度，移动的时候需要
	
	private GestureDetector mGestureDetector;
	
	
	LocalActivityManager manager = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        
        
        FragmentTransaction transaction = this.getSupportFragmentManager().beginTransaction();
        RightFragment rightFrag = new RightFragment();
        slidingMenu.setSecondaryMenu(R.layout.right_frame);
        transaction.replace(R.id.right_frame, rightFrag);
        transaction.commit();
        
        
        
        
        
        //setContentView(R.layout.main);
        
        setContentView(R.layout.layout_news);
        
        
		mGestureDetector = new GestureDetector(this);
		mGestureDetector.setIsLongpressEnabled(false);
        
        
		manager = new LocalActivityManager(this , true);
        manager.dispatchCreate(savedInstanceState);
		
		
        initViews();
        
        
        bottom_layout = (RelativeLayout) findViewById(R.id.layout_bottom);
        
/*
		tabHost = getTabHost();
		
        tabHost.addTab(tabHost.newTabSpec("news").setIndicator("News").setContent(new Intent(this, TabNewsActivity.class)));
        tabHost.addTab(tabHost.newTabSpec("topic").setIndicator("Topic").setContent(new Intent(this, TabTopicActivity.class)));
        tabHost.addTab(tabHost.newTabSpec("picture").setIndicator("Picture").setContent(new Intent(this, TabPicActivity.class)));
        tabHost.addTab(tabHost.newTabSpec("follow").setIndicator("Follow").setContent(new Intent(this, TabFollowActivity.class)));
        tabHost.addTab(tabHost.newTabSpec("vote").setIndicator("Vote").setContent(new Intent(this, TabVoteActivity.class)));
        
        radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
        radioGroup.setOnCheckedChangeListener(checkedChangeListener);
        
        img = new ImageView(this);
        img.setImageResource(R.drawable.tab_front_bg);
        bottom_layout.addView(img);
 */       
        
        
        
        /*
        LayoutInflater inflater = getLayoutInflater();
		list = new ArrayList<View>();
		list.add(inflater.inflate(R.layout.vpage1, null));
		list.add(inflater.inflate(R.layout.vpage2, null));
		list.add(inflater.inflate(R.layout.vpage3, null));
		
		//list.add(inflater.inflate(R.layout.vpage3, null));
		//list.add(inflater.inflate(R.layout.vpage3, null));

		

		imageViews = new ImageView[list.size()];
		ViewGroup main = (ViewGroup) inflater.inflate(R.layout.main, null);
		
		ViewGroup group = (ViewGroup) main.findViewById(R.id.viewGroup);

		viewPager = (ViewPager) main.findViewById(R.id.viewPager);

		for (int i = 0; i < list.size(); i++) {
			imageView = new ImageView(MainActivity.this);
			imageView.setLayoutParams(new LayoutParams(12,12));
			//imageView.setPadding(10, 0, 10, 0);
			imageViews[i] = imageView;
			if (i == 0) {
				
				imageViews[i].setBackgroundResource(R.drawable.ic_launcher);
			} else {
				imageViews[i].setBackgroundResource(R.drawable.ic_launcher);
			}
			group.addView(imageView);
		}

		setContentView(main);

		viewPager.setAdapter(new MyAdapter());
		viewPager.setOnPageChangeListener(new MyListener());
		viewPager.setCurrentItem(300);
       
        
        
        
        
        
        
        
        
        
        ListView listView = (ListView) findViewById(R.id.mainList);

        //生成动态数组，并且转载数据
        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
        for(int i=0;i<30;i++)
        {
        	HashMap<String, String> map = new HashMap<String, String>();
        	map.put("ItemTitle", "This is Title.....");
        	map.put("ItemText", "This is text.....");
        	mylist.add(map);
        }
        //生成适配器，数组===》ListItem
        SimpleAdapter mSchedule = new SimpleAdapter(this, //没什么解释
        		                                    mylist,//数据来源 
        		                                    R.layout.vlist,//ListItem的XML实现
        		                                    
        		                                    //动态数组与ListItem对应的子项        
        		                                    new String[] {"ItemTitle", "ItemText"}, 
        		                                    
        		                                    //ListItem的XML文件里面的两个TextView ID
        		                                    new int[] {R.id.ItemTitle,R.id.ItemText});
        //添加并且显示
        listView.setAdapter(mSchedule);
        
        */
        
        
        
        
        
    }
    
    
    /*
	private OnCheckedChangeListener checkedChangeListener = new OnCheckedChangeListener() {

		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			switch (checkedId) {
			case R.id.radio_news:
				tabHost.setCurrentTabByTag("news");
				MoveBg.moveFrontBg(img, startLeft, 0, 0, 0);
				startLeft = 0;
				break;
			case R.id.radio_topic:
				tabHost.setCurrentTabByTag("topic");
				MoveBg.moveFrontBg(img, startLeft, img.getWidth(), 0, 0);
				startLeft = img.getWidth();
				break;
			case R.id.radio_pic:
				tabHost.setCurrentTabByTag("picture");
				MoveBg.moveFrontBg(img, startLeft, img.getWidth() * 2, 0, 0);
				startLeft = img.getWidth() * 2;
				break;
			case R.id.radio_follow:
				tabHost.setCurrentTabByTag("follow");
				MoveBg.moveFrontBg(img, startLeft, img.getWidth() * 3, 0, 0);
				startLeft = img.getWidth() * 3;
				break;
			case R.id.radio_vote:
				tabHost.setCurrentTabByTag("vote");
				MoveBg.moveFrontBg(img, startLeft, img.getWidth() * 4, 0, 0);
				startLeft = img.getWidth() * 4;
				break;

			default:
				break;
			}
		}
	};
	
	
	
	
	
	
	
	

	class MyAdapter extends PagerAdapter {

		@Override
		public int getCount() {
			return Integer.MAX_VALUE;
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == arg1;
		}

		@Override
		public int getItemPosition(Object object) {
			// TODO Auto-generated method stub
			return super.getItemPosition(object);
		}

		@Override
		public void destroyItem(View arg0, int arg1, Object arg2) {
			// TODO Auto-generated method stub
			//((ViewPager) arg0).removeView(list.get(arg1));
		}

		@Override
		public Object instantiateItem(View arg0, int arg1) {
			// TODO Auto-generated method stub
			    try{
					((ViewPager) arg0).addView(list.get(arg1%list.size()),0);
				    }catch (Exception e) {
						// TODO: handle exception
					}
				return list.get(arg1%list.size());
		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {
			// TODO Auto-generated method stub

		}

		@Override
		public Parcelable saveState() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
			// TODO Auto-generated method stub

		}

		@Override
		public void finishUpdate(View arg0) {
			// TODO Auto-generated method stub

		}
	}
	

	class MyListener implements OnPageChangeListener {

		//当滑动状态改变时调用  
		@Override
		public void onPageScrollStateChanged(int arg0) {
			// TODO Auto-generated method stub
			//arg0=arg0%list.size();
			
		}

		//当当前页面被滑动时调用  
		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
			// TODO Auto-generated method stub
			
		}

		//当新的页面被选中时调用  
		@Override
		public void onPageSelected(int arg0) {
			 if(arg0>2){
				    arg0=arg0%list.size();
				   }
			c_id = arg0;
			for (int i = 0; i < imageViews.length; i++) {
				imageViews[arg0]
						.setBackgroundResource(R.drawable.ic_launcher);
				if (arg0 != i) {
					imageViews[i]
							.setBackgroundResource(R.drawable.ic_launcher);
				}
			}
			
			Log.e("-------------", "当前是第"+c_id+"页");
		}

	}
	*/
	
	
	
	private void initViews() {
		
			

		//followMenuLayout = (RelativeLayout) findViewById(R.id.layout);	

		
		
		layout = (RelativeLayout) findViewById(R.id.layout_title_bar);
		layout_news_main = (RelativeLayout) findViewById(R.id.layout_news_main);
		layout_news_main.setOnTouchListener(onTouchListerner);
		
		inflater = getLayoutInflater();
		
		menuBtn = (ToggleButton) findViewById(R.id.menuBtn);		
		settingBtn = (ToggleButton) findViewById(R.id.settingBtn);

		tv_bar_news = (TextView) findViewById(R.id.tv_title_bar_news);
		tv_bar_sport = (TextView) findViewById(R.id.tv_title_bar_sport);
		tv_bar_play = (TextView) findViewById(R.id.tv_title_bar_play);
		tv_bar_finance = (TextView) findViewById(R.id.tv_title_bar_finance);
		tv_bar_science = (TextView) findViewById(R.id.tv_title_bar_science);
		tv_bar_more = (TextView) findViewById(R.id.tv_title_bar_more);

		

		


    	
		
	    
		menuBtn.setOnClickListener(onClickListener);		
		settingBtn.setOnClickListener(onClickListener);
		
		//followMenuLayout.setOnClickListener(onClickListener);
	    		
		
		
		
		tv_bar_news.setOnClickListener(onClickListener);
		tv_bar_sport.setOnClickListener(onClickListener);
		tv_bar_play.setOnClickListener(onClickListener);
		tv_bar_finance.setOnClickListener(onClickListener);
		tv_bar_science.setOnClickListener(onClickListener);
		tv_bar_more.setOnClickListener(onClickListener);

		tv_front = new TextView(this);
		tv_front.setBackgroundResource(R.drawable.slidebar);
		tv_front.setTextColor(Color.WHITE);
		tv_front.setText("头条");
		tv_front.setGravity(Gravity.CENTER);
		RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		param.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
		layout.addView(tv_front, param);
		
		//默认显示“头条”
		intent = new Intent(MainActivity.this, TabNewsTopActivity.class);
		intent.putExtra("title", HttpRequestUrl.URL_NEWS_TOP);

		
		page = manager.startActivity("activity1", intent).getDecorView();
		//page = getLocalActivityManager().startActivity("activity1", intent).getDecorView();
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		layout_news_main.addView(page, params);
		
		
		
	}
	
    
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) 
	{
		if(resultCode == Activity.RESULT_OK && requestCode == LOGIN_RESULT)
		{
			System.out.println("RightFragment-->onActivityResult");
			
			
	    	if (Users.user != null)
	    	{
	    		String u = Users.user.getUserName();
	    		
	    		RightFragment rFrag = (RightFragment)  getSupportFragmentManager().findFragmentById(R.id.right_frame);  
	    		TextView tv =  (TextView)rFrag.getView().findViewById(R.id.userTitle);

	    		
	    		
	    		tv.setText(u + "");
	    		
	    		

	    		
	    		
	    		//userTitle.setText(u + "pppp");
	    	}
	    	else
	    	{
	    		//userTitle.setText("登录帐号");
	    	}
			
			
			
		}
		super.onActivityResult(requestCode, resultCode, data);
	}   
    
	
	
	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        //getMenuInflater().inflate(R.menu.activity_main, menu);
		//toggle();
		
		//getSlidingMenu().showMenu(true);
		
        
		//return false;
        
        return super.onCreateOptionsMenu(menu);
    }
	
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            //toggle就是程序自动判断是打开还是关闭
            toggle();
			//getSlidingMenu().showMenu();// show menu
			//getSlidingMenu().showContent();//show content
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    /*
    @Override  
    public boolean dispatchKeyEvent(KeyEvent event) 
    {  
        // TODO Auto-generated method stub   
    	Log.i("  dispatchKeyEvent 1 key = " + event.getKeyCode() + " event =  " + event.getAction(), "");  
        
        if(event.getAction()==KeyEvent.ACTION_DOWN)
        {  
        	Log.i("  dispatchKeyEvent 2 ACTION_DOWN" + event.getKeyCode() , "");  
            return true;  
        }
        
        if(event.getAction()==KeyEvent.ACTION_UP)
        {  
        	Log.i("  dispatchKeyEvent 3 ACTION_UP" + event.getKeyCode() , "");  
            return false;  
        }  
        return super.dispatchKeyEvent(event);  
    }  
    */
    
	@Override 
	public boolean onKeyDown(int keyCode, KeyEvent event) 
	{ 
		
		//Log.i("event.getRepeatCount(): ", event.getRepeatCount() + "");
		
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) 
		{ 
			//ExitUtils.ExitWithDoubleClick(this);
			//Log.i("00000000000000000000", event.getRepeatCount() + "");
			
			if (slidingMenu.isSecondaryMenuShowing() || slidingMenu.isMenuShowing())
    		{
    			slidingMenu.showContent();
    			
    			//dispatchKeyEvent(event); 
    			//Log.i("1111111111111111111", event.getRepeatCount() + "");
    		}
			else 
			{
				//Log.i("222222222222222222222", event.getRepeatCount() + "");
				//finish();
				ExitUtils.ExitWithDoubleClick(this);
			}

			
			return true; 
		}
		else if (keyCode == KeyEvent.KEYCODE_MENU )
    	{
    		if (slidingMenu.isSecondaryMenuShowing())
    		{
    			slidingMenu.showContent();
    		}
    		else
    		{
    			slidingMenu.showSecondaryMenu();
    		}
        	
            return true;        	
        	
        }

		//Log.i("3333333333333333333333", event.getRepeatCount() + "");
		//return super.onKeyDown(keyCode, event);
		return false;
	}
	
    
    
    

	private OnClickListener onClickListener = new OnClickListener() {
		int startX;//移动的起始位置
		/*		
		@Override
		public void onClick(View v) {
			
		}
*/
		
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		@Override
		public void onClick(View v) {
			avg_width = findViewById(R.id.layout).getWidth();
			switch (v.getId()) {
			/*
			case R.id.layout:
				
				Log.e("layout: ", "onFollowClickListener");
				
				break;
				*/
			case R.id.menuBtn:
	    		if (slidingMenu.isMenuShowing()){
	    			slidingMenu.showContent();
	    		}else{
	    			slidingMenu.showMenu();
	    		}
				
				break;			
			case R.id.settingBtn:
				
	    		if (slidingMenu.isSecondaryMenuShowing()){
	    			slidingMenu.showContent();
	    		}else{
	    			slidingMenu.showSecondaryMenu();
	    		}
				break;			
			
			case R.id.tv_title_bar_news:
				MoveBg.moveFrontBg(tv_front, startX, 0, 0, 0);
				startX = 0;
				tv_front.setText(R.string.title_news_category_tops);
				//准备显示“头条”
				page = inflater.inflate(R.layout.layout_news_top, null);
				intent.setClass(MainActivity.this, TabNewsTopActivity.class);
				intent.putExtra("title", HttpRequestUrl.URL_NEWS_TOP);
				page = manager.startActivity("activity1", intent).getDecorView();
				break;
			case R.id.tv_title_bar_sport:
				MoveBg.moveFrontBg(tv_front, startX, avg_width, 0, 0);
				startX = avg_width;
				tv_front.setText(R.string.title_news_category_sport);
				//准备显示“体育”
				intent.setClass(MainActivity.this, TabNewsSportActivity.class);
				intent.putExtra("title", HttpRequestUrl.URL_NEWS_SPORT);
				page = manager.startActivity("activity2", intent).getDecorView();
				break;
			case R.id.tv_title_bar_play:
				MoveBg.moveFrontBg(tv_front, startX, avg_width * 2, 0, 0);
				startX = avg_width * 2;
				tv_front.setText(R.string.title_news_category_play);
				//准备显示“娱乐”
				intent.setClass(MainActivity.this, TabNewsPlayActivity.class);
				intent.putExtra("title", HttpRequestUrl.URL_NEWS_PLAY);
				page = manager.startActivity("activity3", intent).getDecorView();
				break;
			case R.id.tv_title_bar_finance:
				MoveBg.moveFrontBg(tv_front, startX, avg_width * 3, 0, 0);
				startX = avg_width * 3;
				tv_front.setText(R.string.title_news_category_finance);
				//准备显示“财经”
				intent.setClass(MainActivity.this, TabNewsFinanceActivity.class);
				intent.putExtra("title", HttpRequestUrl.URL_NEWS_FINANCE);
				page = manager.startActivity("activity4", intent).getDecorView();
				break;
			case R.id.tv_title_bar_science:
				MoveBg.moveFrontBg(tv_front, startX, avg_width * 4, 0, 0);
				startX = avg_width * 4;
				tv_front.setText(R.string.title_news_category_science);
				//准备显示“科技”
				intent.setClass(MainActivity.this, TabNewsScienceActivity.class);
				intent.putExtra("title", HttpRequestUrl.URL_NEWS_SCIENCE);
				page = manager.startActivity("activity5", intent).getDecorView();
				break;
			case R.id.tv_title_bar_more:
				MoveBg.moveFrontBg(tv_front, startX, avg_width * 5, 0, 0);
				startX = avg_width * 5;
				tv_front.setText(R.string.title_news_category_more);
				//准备显示“更多”
				intent.setClass(MainActivity.this, TabNewsMoreActivity.class);
				page = manager.startActivity("activity6", intent).getDecorView();
				break;

			default:
				break;
			}
			//切换
			layout_news_main.removeAllViews();
			layout_news_main.addView(page, params);
			
		}
		
		
	};
	
//手指在屏幕上移动距离小于此值不会被认为是手势
	private static final int SWIPE_MIN_DISTANCE = 120;
	//手指在屏幕上移动速度小于此值不会被认为手势
	private static final int SWIPE_THRESHOLD_VELOCITY = 200;
	
	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,	float velocityY) {
		
		

				
		//手势识别函数，到此函数被系统回调时说明系统认为发生了手势事件，
		//我们可以做进一步判定。

		//如果第1个坐标点大于第二个坐标点，说明是向左滑动
		//滑动距离以及滑动速度是额外判断，可根据实际情况修改。
		if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
			//left
			Log.i("GestureDemo", "ViewFlipper left");
			//mVf.showNext();
//            toggle();
//          getSlidingMenu().showMenu();// show menu
//          getSlidingMenu().showContent();//show content
			
			//onScroll(velocityX);
			return true;
		}else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
			//right
			Log.i("GestureDemo", "ViewFlipper right");
			//mVf.showPrevious();	
			
			
			//onScroll(velocityX);
			return true;
		}
		
		
		
		
		
		
		
		
		
		
		
		return false;
	}
	
	@Override
	public void onLongPress(MotionEvent e) {
		
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		//onScroll(distanceX);
		return false;
	}

	@Override
	public void onShowPress(MotionEvent arg0) {
		
	}
	
	@Override
	public boolean onDown(MotionEvent e) {
		/*
		bIsScrolling = false;
		mScroll = 0;
		iLimited = 0;
		RelativeLayout.LayoutParams lp = (LayoutParams) mainLayout.getLayoutParams();
		if(lp.leftMargin > 0){
			iLimited = 1;
		}else if(lp.leftMargin < 0){
			iLimited = -1;
		}
		*/
		
		return true;
	}
	

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		/*
		 * 	正常情况下，mainLayout的leftMargin为0,
		 * 	当左/右菜单为打开中，此时就不为0，需要判断
		 */
		/*
		if(mClickedView != null){
			RelativeLayout.LayoutParams lp = (LayoutParams) mainLayout.getLayoutParams();
			
			if(mClickedView == ivMore){
				Log.d(TAG, "[onSingleTapUp] ivMore clicked! leftMargin = " + lp.leftMargin);
				
				if(lp.leftMargin == 0){
					new SlideMenu().execute(leftLayout.getLayoutParams().width, SPEED);
				}else{
					new SlideMenu().execute(leftLayout.getLayoutParams().width, -SPEED);
				}
			}else if(mClickedView == ivSettings){
				Log.d(TAG, "[onSingleTapUp] ivSettings clicked! leftMargin = " + lp.leftMargin);
				
				if(lp.leftMargin == 0){
					new SlideMenu().execute(rightLayout.getLayoutParams().width, -SPEED);
				}else{
					new SlideMenu().execute(rightLayout.getLayoutParams().width, SPEED);
				}
			}else if(mClickedView == mainLayout){
				Log.d(TAG, "[onSingleTapUp] mainLayout clicked!");
			}
		}
		
		*/
		return true;
	}
	
	
	
	
	
	private OnTouchListener onTouchListerner = new OnTouchListener()
	{

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			// TODO Auto-generated method stub
			
    		Log.i("onTouch", "--------------------------------");
    		
    		if(MotionEvent.ACTION_UP == event.getAction() ){
    			
    			
    		}
    		
    		/*
    		 因为我的手势是定义在leftPanel这个View中的，所以是leftPanel.getGestureDetector().onTouchEvent(event);。
    		 如果你的手势是写在Activity中的，那么就是mGestureDetector.onTouchEvent(event); 
			这样既能保证在ListView上实现拖动，又能保证ListView上的Item Click. 

    		  
    		 * 
    		 */
    		
    		
    		//mainLayout.setOnTouchListener(this);
    		
    		//layoutSlideMenu.getGestureDetector().onTouchEvent(event);//需要这样写！ 

    		
    		mGestureDetector.onTouchEvent(event);
    		
    		return true;
			
			
			
			
			//return false;
		}
		
		
		
		
		
	};
	
	
	
	
	
	
	

	@Override
	protected void onDestroy() {
		Users.user = null;
		super.onDestroy();
	}
}